package com.tfj.mvp.tfj.detail.advisor.detail;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.hyphenate.tfj.R;
import com.tfj.mvp.base.BaseActivity;
import com.tfj.mvp.tfj.detail.advisor.detail.bean.RecordBean;
import com.tfj.mvp.tfj.home.adapter.LiveHomeAdapter;
import com.tfj.mvp.tfj.home.bean.HomeLiveBean;
import com.tfj.mvp.tfj.live.bean.LiveBean;
import com.tfj.mvp.tfj.msg.VMsgFragment;
import com.tfj.mvp.tfj.msg.VMsgParentFragment;
import com.tfj.utils.MyGridLayoutManager;
import com.tfj.utils.ViewFindUtils;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Liang_Lu on 2017/12/21.
 *
 * @author HuangQiang
 * @github https://github.com/HuangQiang
 */

public class VAdvisorDetailActivity extends BaseActivity<PAdvisorDetailImpl> implements CAdvisorDetail.IVAdvisorDetail,OnTabSelectListener {


    @BindView(R.id.rl_live)
    RelativeLayout rlLive;
    @BindView(R.id.recyclew_record)
    RecyclerView recyclewRecord;
    @BindView(R.id.recyclew_content)
    RecyclerView recyclewContent;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "直播", "录播"
    };
    private MyPagerAdapter mAdapter;

    @Override
    protected void initView() {
        super.initView();
        setTitleText("置业顾问详情");
        for (String title : mTitles) {
            mFragments.add(new VFragmentLive(title));
        }
        View decorView =  getWindow().getDecorView();
        ViewPager vp = ViewFindUtils.find(decorView, R.id.vp);
        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        vp.setAdapter(mAdapter);
        SlidingTabLayout tabLayout = ViewFindUtils.find(decorView, R.id.tl);
        tabLayout.setViewPager(vp);
        vp.setCurrentItem(0);
        tabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                rlLive.setVisibility(position==0?View.VISIBLE:View.GONE);
                recyclewRecord.setVisibility(position==1?View.VISIBLE:View.GONE);
            }

            @Override
            public void onTabReselect(int position) {
            }
        });
        //录播数据
        List<RecordBean> recordBeans = new ArrayList<>();
        recordBeans.add(new RecordBean());
        recordBeans.add(new RecordBean());
        recordBeans.add(new RecordBean());
        recordBeans.add(new RecordBean());
        recordBeans.add(new RecordBean());
        MyGridLayoutManager myGridLayoutManager = new MyGridLayoutManager(this, 2);
        myGridLayoutManager.setScrollEnabled(false);
        recyclewRecord.setLayoutManager(myGridLayoutManager);
        recyclewRecord.setAdapter(quickAdapter_buildInfo);
        quickAdapter_buildInfo.replaceData(recordBeans);
        //直播推荐
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclewContent.setLayoutManager(linearLayoutManager);
        LiveHomeAdapter liveHomeAdapter = new LiveHomeAdapter(this);
        recyclewContent.setAdapter(liveHomeAdapter);
        List<LiveBean> liveBeans = new ArrayList<>();
        liveBeans.add(new LiveBean());
        liveBeans.add(new LiveBean());
        liveBeans.add(new LiveBean());
        liveBeans.add(new LiveBean());
        liveBeans.add(new LiveBean());
        liveHomeAdapter.replaceData(liveBeans);

    }

    @Override
    public int setContentViewId() {
        return R.layout.activity_advisordetail;
    }

    @Override
    public void createPresenter() {
        mPresenter = new PAdvisorDetailImpl(mContext, this);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    private QuickAdapter_Record quickAdapter_buildInfo = new QuickAdapter_Record();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void onTabSelect(int position) {
    }

    @Override
    public void onTabReselect(int position) {

    }

    public class QuickAdapter_Record extends BaseQuickAdapter<RecordBean, BaseViewHolder> {
        public QuickAdapter_Record() {
            super(R.layout.item_advisor_record);
        }

        @Override
        protected void convert(BaseViewHolder viewHolder, final RecordBean item) {
        }
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }

}
